<template>
    <div class="minishop-login tc">
        <div class="">
            <img class="logo" mode="widthFix" src="/static/images/logo.png" alt="">
        </div>
        <div class="pt24 ">
            <img class="hello" mode="widthFix" src="/static/images/hello.png" alt="">
        </div>
        <div class="pt40">
            <div class="show-author-wrap">
                <button v-if="checkXy==1" open-type="getUserInfo" class='show-author' @getuserinfo="getUserInfo">获取用户信息</button>
                <img @click="login" class="btn" mode="widthFix" src="/static/images/login-btn.png" alt="">
            </div>
        </div>
        <div class="pt15">
            <div class="inline-block">
                <van-radio-group :value="checkXy" v-on:change="checkChange">
                    <van-radio  icon-size="14px" checked-color="#cda058" name="1">
                        <span class="c-9a9a9a fs-12">我已阅读并同意 <span @click.stop="link('/index/yhxy')">《用户协议》</span> 和 <span @click.stop="link('/index/yszc')">《隐私政策》</span></span>
                    </van-radio>
                </van-radio-group>
            </div>
        </div>
        <div class="c-3f5683 fs-15 pt15" @click="back">暂不登录，我先逛逛</div>
    </div>
</template>

<script>
import userApi from "@/api/api-user";
export default {
    data () {
        return {
            checkXy: ""
        }
    },
    watch: {
        
    },
    components: {
        
    },
    onLoad(options){
         
    },
    mounted () {
        
    },
    onShow(){
        
    },
    methods: {
        back(){
            wx.switchTab({
                url: "/pages/index/index"
            })
        },
        checkChange(e){
            this.checkXy = e.mp.detail
        },
        login(){
            if(this.checkXy==1){
                return
            }
            wx.showToast({
                title: "请先阅读并同意《用户协议》和《隐私政策》",
                icon: "none",
                duration: 2000
            })
        },
        getUserInfo(e){
            var detail = e.mp.detail
            if(detail.errMsg == 'getUserInfo:ok'){
                wx.showLoading({
                    title: '加载中',
                })
                userApi.UpdateUserInfoByWx({
                    sessionId: this.$store.getters.user.sessionId,
                    encryptedData: detail.encryptedData,
                    signature: detail.signature,
                    rawData: detail.rawData,
                    iv: detail.iv
                }).then(res => {
                    this.GetUserInfo()
                }).catch(e=>{
                    wx.hideLoading({})
                })
            } else {
                wx.showToast({
                    title: "您拒绝了授权信息，无法进行该操作",
                    icon: "none",
                    duration: 2000
                })
            }
        },
        GetUserInfo(e){
            var vm = this
            userApi.GetUserInfo({}).then(res => {
                wx.hideLoading({})
                vm.$store.dispatch('SetLoginUser', res.result)
                wx.showToast({
                    title: "授权成功",
                    icon: "success",
                    duration: 2000
                })
                setTimeout(()=>{
                    wx.navigateBack({})
                }, 2000)
            }).catch(e=>{
                wx.hideLoading({})
            })
        },
    }
}
</script>

<style  lang="scss">
@import './scss/login.scss';
</style>
